//
//  MyReplyTableViewCell.m
//  parent
//
//  Created by IreWesT on 15/5/29.
//  Copyright (c) 2015年 ci123. All rights reserved.
//

#import "MyReplyTableViewCell.h"
#import "UIViewExt.h"
#import "UIImageView+WebCache.h"

@implementation MyReplyTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self _initView];
    }
    return self;
}

//初始化子视图
- (void)_initView {
    
    self.contentView.backgroundColor = UIColorMake(244, 244, 244);
    
    _wrapView = [[UIView alloc] initWithFrame:CGRectMake(8, 8, APP_SCREEN_WIDTH - 16, ReplyHeight - 16)];
    _wrapView.backgroundColor = [UIColor whiteColor];
    _wrapView.layer.borderWidth = 1.0f;
    _wrapView.layer.borderColor = UIColorMake(200, 200, 200).CGColor;
    [self.contentView addSubview:_wrapView];
    
    _headView = [[UIImageView alloc] initWithFrame:CGRectMake(7.5, 5, 30, 30)];
    _headView.backgroundColor = [UIColor clearColor];
    _headView.layer.borderColor = UIColorMake(202, 202, 202).CGColor;
    _headView.layer.borderWidth = .5f;
    _headView.layer.cornerRadius = 15.0f;
    _headView.layer.masksToBounds = YES;
    [_wrapView addSubview:_headView];
    
    _nickname = [[UILabel alloc] initWithFrame:CGRectMake(_headView.right + 10, _headView.top + 2, 120, 15)];
    _nickname.backgroundColor = [UIColor clearColor];
    _nickname.textColor = UIColorMake(45, 152, 171);
    _nickname.font = [UIFont systemFontOfSize:15.0f];
    [_wrapView addSubview:_nickname];
    
    _date = [[UILabel alloc] initWithFrame:CGRectMake(_nickname.left, _nickname.bottom + 6, _nickname.width, 12)];
    _date.backgroundColor = [UIColor clearColor];
    _date.textColor = UIColorMake(143, 143, 143);
    _date.font = [UIFont systemFontOfSize:12.0f];
    [_wrapView addSubview:_date];
    
    _content = [[UILabel alloc] initWithFrame:CGRectMake(_headView.left, _headView.bottom + 10, _wrapView.width - _headView.left * 2, 20)];
    _content.backgroundColor = [UIColor clearColor];
    _content.textColor = UIColorMake(55, 55, 55);
    _content.font = [UIFont systemFontOfSize:14.0f];
    _content.lineBreakMode = NSLineBreakByTruncatingTail;
    [_wrapView addSubview:_content];
    
    CALayer *borderMiddle = [CALayer layer];
    borderMiddle.backgroundColor = UIColorMake(200, 200, 200).CGColor;
    borderMiddle.frame = CGRectMake(0, _content.bottom + 10, _wrapView.width, 1);
    [_wrapView.layer addSublayer:borderMiddle];
    
    _post = [[UILabel alloc] initWithFrame:CGRectMake(_headView.left, _content.bottom + 20, _wrapView.width - _headView.left * 2, 20)];
    _post.backgroundColor = [UIColor clearColor];
    _post.textColor = UIColorMake(55, 55, 55);
    _post.font = [UIFont systemFontOfSize:14.0f];
    _post.lineBreakMode = NSLineBreakByTruncatingTail;
    [_wrapView addSubview:_post];
    
    CALayer *border = [CALayer layer];
    border.backgroundColor = UIColorMake(200, 200, 200).CGColor;
    border.frame = CGRectMake(0, _wrapView.height - 31, _wrapView.width, 1);
    [_wrapView.layer addSublayer:border];
    
    _circle = [[UILabel alloc] initWithFrame:CGRectMake(_headView.left, border.frame.origin.y, 60, 30)];
    _circle.backgroundColor = [UIColor clearColor];
    _circle.font = [UIFont systemFontOfSize:12.0f];
    _circle.textColor = UIColorMake(152, 152, 152);
    [_wrapView addSubview:_circle];
    
    _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(_wrapView.width - 25, _circle.top, 25, 30)];
    _countLabel.backgroundColor = [UIColor clearColor];
    _countLabel.font = [UIFont systemFontOfSize:12.0f];
    _countLabel.textColor = UIColorMake(117, 158, 190);
    [_wrapView addSubview:_countLabel];
    
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(_countLabel.left - 5 - 22, _countLabel.top + 8, 22, 14)];
    icon.backgroundColor = [UIColor clearColor];
    icon.image = [UIImage imageNamed:@"mypost_icon_count"];
    [_wrapView addSubview:icon];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
     [_headView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",AVATAR_HEADER,_pic]]];
    _nickname.text = [NSString stringWithFormat:@"%@", _name];
    _date.text = [NSString stringWithFormat:@"%@", _data[@"time"]];
    _content.text = [NSString stringWithFormat:@"回复：%@", _data[@"content"]];
    _post.text = [NSString stringWithFormat:@"原帖：%@", _data[@"srcpost"][@"title"]];
    _circle.text = [NSString stringWithFormat:@"%@", _circleName];
    _countLabel.text = [NSString stringWithFormat:@"%@", _data[@"srcpost"][@"replynum"]];
}

@end
